// 这是公益活动接口
import axios from '@/utils/axios'

import type { AxiosDefaultTypes } from '@/utils/axios'
import type { AxiosResponse } from 'axios'
import type { AxiosActivityListTypes } from './types'

export * from './types'

// 添加公益活动
/**
 *
 * @param name 活动名称
 * @param des 活动介绍
 * @param place 活动地址
 * @param startTime 活动开始时间
 * @param endTime 活动结束时间
 */
export const addActivity: (
  name: string,
  des: string,
  place: string,
  startTime: number,
  endTime: number
) => Promise<AxiosResponse<AxiosDefaultTypes<null>, any>> = (
  name: string,
  des: string,
  place: string,
  startTime: number,
  endTime: number
) => {
  return axios.post<AxiosDefaultTypes<null>>('/api/activity/add', {
    name,
    des,
    place,
    startTime,
    endTime
  })
}

// 获取活动列表
/**
 *
 * @param limit 请求数据数量
 * @param skip 数据偏移量
 * @returns 数据列表和总数
 */
export const getActivityList: (
  limit: number,
  skip: number
) => Promise<AxiosResponse<AxiosDefaultTypes<AxiosActivityListTypes>, any>> = (
  limit: number,
  skip: number
) => {
  return axios.get<AxiosDefaultTypes<AxiosActivityListTypes>>(
    '/api/activity/getAll',
    {
      params: {
        limit,
        skip
      }
    }
  )
}

// 更新公益活动
/**
 *
 * @param activityID 公益活动ID
 * @param name 公益活动名称
 * @param des 公益活动描述
 */
export const updateActivity: (
  activityID: string,
  name: string,
  des: string
) => Promise<AxiosResponse<AxiosDefaultTypes<null>, any>> = (
  activityID: string,
  name: string,
  des: string
) => {
  return axios.post<AxiosDefaultTypes<null>>('/api/activity/update', {
    activityID,
    name,
    des
  })
}

// 删除公益活动
/**
 *
 * @param activityID 公益活动ID
 */
export const deleteActivity: (
  activityID: string
) => Promise<AxiosResponse<AxiosDefaultTypes<null>, any>> = (
  activityID: string
) => {
  return axios.post<AxiosDefaultTypes<null>>('/api/activity/delete', {
    activityID
  })
}

// 搜索公益活动
/**
 *
 * @param name 活动名称关键字
 * @param startTime 活动起始时间
 * @param endTime 活动终止时间
 * @param place 活动终止时间
 * @param limit 请求活动数量
 * @param skip 数据偏移量
 */
export const searchActivity: (
  name: string,
  startTime: number,
  endTime: number,
  place: string,
  limit: number,
  skip: number
) => Promise<AxiosResponse<AxiosDefaultTypes<AxiosActivityListTypes>, any>> = (
  name: string,
  startTime: number,
  endTime: number,
  place: string,
  limit: number,
  skip: number
) => {
  return axios.get<AxiosDefaultTypes<AxiosActivityListTypes>>(
    '/api/activity/search',
    {
      params: {
        name,
        startTime,
        endTime,
        place,
        limit,
        skip
      }
    }
  )
}
